{% extends  "cmdb/index.html" %}
{% block title %}服务器硬件信息{% endblock %}
{% block style %}
    <link type="text/css" rel="stylesheet" href="/static/css/ui.jqgrid.css">
    <link rel="stylesheet" type="text/css" media="screen" href="/static/css/jquery-ui-1.7.1.custom.css" />
{% endblock %}

{% block breadcrumb  %}
    <ul class="breadcrumb">
							<li>
								<i class="ace-icon fa fa-home home-icon"></i>
								<a href="#">Home</a>
							</li>
                            <li>
								<i class="ace-icon fa fa-home home-icon"></i>
								<a href="#">服务器管理</a>
							</li>
							<li class="active">服务器硬件信息</li>
						</ul><!-- /.breadcrumb -->
{% endblock %}
{% block page-header %}
<div class="page-header">
    <h1>
        Dashboard
        <small>
            <i class="ace-icon fa fa-angle-double-right"></i>
        服务器管理 &amp; 服务器硬件信息
        </small>
        </h1>
</div><!-- /.page-header -->
{% endblock %}

{% block content %}
{% include "cmdb/hard_search_form.html"  %}
   <div id="mytable">
    <table class="table table-striped" id="gridtable" width="100%" border="0.5">
        <thead>
        <tr>
            <th><input type="checkbox" name="check" id="all"/> </th>
            <th>服务器IP</th>
            <th>osver</th>
            <th>kernel</th>
            <th>cpu_model</th>
            <th>CPU/个</th>
            <th>物理内存/MB</th>
            <th>磁盘/GB</th>
            <th>product</th>
            <th>主机名</th>
            <th>所有信息</th>
        </tr>
        </thead>
        {% for i in posts  %}
            <tr>
            <td><input   type="checkbox" name="check_box" value="{{ i.id }}" /> </td>
            <td class="success" >{{ i.ip }}</td>
            <td class="warning">{{ i.osver }}</td>
                <td class="success">{{ i.kernel }}</td>
            <td class="active" >{{ i.cpu_model }}</td>
            <td class="success" >{{ i.cpu_num }}</td>
            <td class="active" >{{ i.mem }}</td>
            <td class="active" >{{ i.disk }}</td>
            <td class="success" >{{ i.product }}</td>
            <td class="success" >{{ i.hostname }}</td>
            <td class="warning"><input class="btn btn-warning" type="button" id="edit" value="查看" onclick="cat_all_info({{ i.id }})" /></td>
            </tr>
        {% endfor %}
    </table>
   </div>
    
     <div class="text-center">
    <label for="select">每页数据条数:</label>
    <select  id="mySelect">
        <option selected="selected">0</option>
        <option>10</option>
        <option>20</option>
        <option>30</option>
    </select>&nbsp;&nbsp;&nbsp;&nbsp;
    
    <p>pre:{{ prefix }}</p> 
    
    <div class="text-right">
    <ul class="pagination pagination-lg">
        <li class="disabled"><a href="#">&laquo;</a></li>
        {% for var in pagelist %}
            {% ifequal var curpage  %}
            <li class="active"><a href="{% url url_name %}?curpage={{var}}&allpage={{allpage}}"> {{var}}</a></li>

            {% else %}
                <li><a href="{% url url_name  %}?curpage={{var}}&allpage={{allpage}}">{{var}}</a></li>
                {% endifequal %}
        {% endfor %}
    <li ><a href="#">&raquo;</a></li>
    </ul>
    </div>
    </div>



    <!-- jqGrid 分页 div gridPager -->
    <!--jqGrid 浏览导航栏所在-->
<p style="display:none">默认隐藏</p>
<!-- 模态框（Modal） -->
<div class="modal fade" id="mymodal"  >
    <div class="modal-dialog" style="width:520px;">
        <div class="modal-content">
            <p><button class="close" type="button" data-dismiss="modal">×</button></p>
                <hr />
                <!-- 模态弹出窗内容 -->
         <!-- <div class="modal-body">
            <textarea rows="2" cols="50">在这里输入回复</textarea>
         <h2 id="allinfo"> test</h2>  
         </div> -->
         <p id="allinfo">test<p>
         </div>
        <button  id="btn2" type="button" class="btn btn-primary"   data-dismiss="modal">关闭</button>
      </div><!-- /.modal-content -->
</div><!-- /.modal -->


    <div class="modal fade" id="mymodal2"  >
    <div class="modal-dialog" style="width:680px;">
        <div class="modal-content">
            <p><button class="close" type="button" data-dismiss="modal">×</button></p>
                <hr />
                <p id="label_for_edit"  name="label_modal" class="text-center">服务器硬件信息</p>
                <!-- 模态弹出窗内容 -->
         <!-- <div class="modal-body">
            <textarea rows="2" cols="50">在这里输入回复</textarea>

         </div> -->
{#         <h1>system info </h1>#}
            <textarea id="system_text" rows="15" cols="90"></textarea>
            <button  id="btn2" type="button" class="btn btn-primary"   data-dismiss="modal">关闭</button>
         </div>
      </div><!-- /.modal-content -->
</div>
{% endblock %}

    {% block scripts %}
        <script  type="text/javascript" src="/static/js/bootstrap.min.js"></script>

    <script type="text/javascript">
    setCookie('has_post','1');
    function getCookie(name){
    var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");

    if(arr=document.cookie.match(reg))

        return unescape(arr[2]);
    else
        return null;
}
function cat_all_info(abcdef){
    var sid=abcdef;
    var url= "{% url url_name  %}?option=query&r="+Math.random();
   $.ajax({
           type: "POST",
           url:url,
           data: {serverid:sid,csrfmiddlewaretoken:"{{csrf_token}}",option:"query"},
            dataType: "json",
            success: function(ret){
                //$("#allinfo").text(ret.all_info);
                alert(ret.all_info);
            },
                error: function (msg) {
                    alert("Connection error");
                    return  false;
                     }
            });

}


function setCookie(name,value)
{
    var Days = 30;
    var exp = new Date();
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}

function delCookie(name)
{
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval=getCookie(name);
    if(cval!=null)
        document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}

    function postform(){
       var baseurl="{% url url_name %}?&r="+Math.random();
       option=getCookie('option');
       var url = baseurl+"&option="+option;
       delCookie('option');
       $.ajax({
                cache: false,
                type: "POST",
                url:url,
                data:$('#myformid').serialize(),// 你的formid
                async: false,
                dataType: "json",
                error: function(request) {
                    alert("Connection error");
                },
                success: function(data) {
                    alert(data.msg);
                    delCookie('pageper');

                    $("#mymodal").modal('hide');
                    var url="{% url url_name %}?&r="+Math.random();
                    window.location.href=url;
                 }
            }); 
    }

     function check(){
        if (getCookie('has_post') =='ok'){
            alert('ok');
            return false;
        }else {
            setCookie('has_post','ok');
            return true;
        }
    }
$(document).ready(function() {
    //window.onload=onload;

    $('#mySelect').change(function(){
        var per=$(this).children('option:selected').val();
        delCookie('pageper');
        setCookie('pageper',per);
        var url="{% url url_name %}?&r="+Math.random();
        window.location.href=url;
        });





        setCookie('option','update');
{#        $("#mymodal").modal('show');#}

{#    });#}


    $("#all").click(function(){
        if(this.checked){
            $("[name=check_box]:checkbox").prop("checked", true);
        }else{
            $("[name=check_box]:checkbox").removeAttr("checked");
        }
     });





});
    </script>
        {% endblock %}
